<script setup lang="ts">
import { ref } from "vue";
import ReCol from "@/components/ReCol";
import { formRules } from "./utils/rule";
import { FormProps } from "./utils/types";
import { usePublicHooks } from './hooks'
import { useTranslationLang } from "@/layout/hooks/useTranslationLang";
const { locale } = useTranslationLang();
import { useI18n } from "vue-i18n";
const { t } = useI18n();

const props = withDefaults(defineProps<FormProps>(), {
    formInline: () => ({
        name: "",
        status: 1,
        type: 0,
        sort: null,
        note: ""
    }),
    mapTypes: []
});

const ruleFormRef = ref();
const newFormInline = ref(props.formInline);
const mapTypes = ref(props.mapTypes);
const { switchStyle } = usePublicHooks();

function getRef() {
    return ruleFormRef.value;
}

defineExpose({ getRef });
</script>

<template>
    <el-form ref="ruleFormRef" :model="newFormInline" :rules="formRules" label-width="82px"
        :label-position="locale === 'en' ? 'top' : 'right'">
        <el-row :gutter="30">
            <re-col :value="24" :xs="24" :sm="24">
                <el-form-item :label="t('map.mapName')" prop="name">
                    <el-input v-model="newFormInline.name" clearable />
                </el-form-item>
            </re-col>
            <re-col :value="24" :xs="24" :sm="24">
                <el-form-item :label="t('map.status')" prop="status">
                    <el-switch v-model="newFormInline.status" inline-prompt :active-value="1" :inactive-value="0"
                        :active-text="t('map.enable')" :inactive-text="t('map.disable')" :style="switchStyle" />
                </el-form-item>
            </re-col>
            <re-col :value="24" :xs="24" :sm="24">
                <el-form-item :label="t('map.mapType')" prop="type">
                    <el-select v-model="newFormInline.type" style="width:100%">
                        <el-option v-for="item in mapTypes" :key="Number(item.Value)" :label="item.Name"
                            :value="Number(item.Value)" />
                    </el-select>
                </el-form-item>
            </re-col>
            <re-col :value="24" :xs="24" :sm="24">
                <el-form-item :label="t('map.sort')" prop="sort">
                    <el-input-number v-model="newFormInline.sort" controls-position="right" />
                </el-form-item>
            </re-col>
            <re-col :value="24" :xs="24" :sm="24">
                <el-form-item :label="t('map.remarks')" prop="note">
                    <el-input v-model="newFormInline.note" clearable type="textarea" />
                </el-form-item>
            </re-col>
        </el-row>
    </el-form>
</template>

<style lang="scss" scoped>
.el-radio {
    margin-right: 16px;
}
</style>
